home *** CD-ROM | disk | FTP | other *** search
/ Aminet 32 / Aminet 32 (1999)(Schatztruhe)[!][Aug 1999].iso / Aminet / biz / patch / CrossDOS704.lha / Patcher < prev    next >
Text File  |  1998-01-08  |  9KB  |  308 lines

  1. ;Script to apply patches
  2. ;$VER: Patcher 7.01 (8.1.98)
  3. ;Copyright © 1992-1994 CONSULTRON.  All rights reserved
  4. ; Use of this script in commercial products is expressly forbidden without
  5. ; written permission.
  6. ;
  7. ; The program spatch is provided by SAS Institute.  They retain all copyrights
  8. ; to that program.  It is available for commercial distribution only to those
  9. ; users who have purchased their SAS C Compiler and are registered with them.
  10.  
  11. ;***************************************************************************
  12.  
  13. ;Copy a new file to the product disk
  14. ;Input: newfile (path and name of new file)
  15.  
  16. (procedure copynew
  17.     (    (if (not PatchOnly)
  18.             (    (if (getsize ("%ld/%s" wversion newfile) )
  19.                     (    (if (not DeleteOnly)
  20.                             (    (copyfiles
  21.                                     (source ("%ld/%s" wversion newfile) )
  22.                                     (dest (pathonly ("%s%s" prod newfile) ) )
  23.                                 )
  24.                             )
  25.                         )
  26.                     )
  27.                     (    (delete ("%s%s" prod newfile) ) )
  28.                 )
  29. ;                (if    (> wversion currentver )
  30. ;                    (set currentver wversion)
  31. ;                )
  32.             )
  33.         )
  34.     )
  35. )
  36.  
  37. ;***************************************************************************
  38.  
  39. ;Perform an spatch
  40. ;Input: file (path and file to patch)
  41.  
  42. (procedure patch
  43.     (    (if (and (not DeleteOnly) (not CopyOnly) )
  44.             (    (set patchfile ("%ld/%s" wversion file) )
  45.                 (set prodfile ("%s%s" prod file) )
  46.                 (set prodfile (substr prodfile 0 (- (strlen prodfile) 1 ) ) )
  47.                 (set tempdir "T:")
  48.                 (set temp ("%s%s" tempdir (fileonly prodfile)))
  49.                 (if    (= 0 (run ("%s -o%s -p%s %s" spatch temp patchfile prodfile) ))
  50. ;                    (if    (> wversion currentver )
  51. ;                        (set currentver wversion)
  52. ;                    )
  53.                 )
  54.                 ;Replace original file with temp file
  55.                 (if (> (getsize temp) 10 )
  56.                     (    ;Clone protection bits
  57.                         (protect temp (protect patchfile) )
  58.                         (copyfiles
  59.                             (source temp)
  60.                             (dest (pathonly prodfile) )
  61.                             (newname (fileonly prodfile) )
  62.                         )
  63.                     )
  64.                 )
  65.                 ;Delete temporary file
  66.                 (delete temp)
  67.             )
  68.         )
  69.     )
  70. )
  71.  
  72.  
  73. ;Apply the spatch stuff
  74. ;Set DeleteOnly for delete phase
  75.  
  76. ;**************************************************************************
  77. (procedure DoPatch
  78.     (    (while (exists ("%ld" wversion) (noreq) )
  79.             (    (foreach ("%ld" wversion) "#?"
  80.                     (    (if (< @each-type 0)    ;check for file
  81.                             (    (if (= "@" (substr @each-name (- (strlen @each-name) 1 )))
  82.                                     (    ;Apply patches with spatch
  83.                                         (set file @each-name)
  84.                                         (patch)
  85.                                     )
  86.                                     (    ;Copy the file directly
  87.                                         (set newfile @each-name)
  88.                                         (copynew)
  89.                                     )
  90.                                 )
  91.                             )
  92.                             (    ;@each-name is a directory
  93.                                 (set dir @each-name)
  94.                                 (foreach ("%ld/%s" wversion dir) "#?"
  95.                                     (    (if (< @each-type 0)    ;check for file
  96.                                             (    (if (= "@" (substr @each-name (- (strlen @each-name) 1 )))
  97.                                                     (    ;Apply patches with spatch
  98.                                                         (set file (tackon dir @each-name))
  99.                                                         (patch)
  100.                                                     )
  101.                                                     (    ;Copy the file directly
  102.                                                         (set newfile (tackon dir @each-name))
  103.                                                         (copynew)
  104.                                                     )
  105.                                                 )
  106.                                             )
  107.                                             (    ;@each-name is a directory
  108.                                                 (set dir2 (tackon dir @each-name))
  109.                                                 (foreach ("%ld/%s" wversion dir2) "#?"
  110.                                                     (    (if (< @each-type 0)    ;check for file 
  111.                                                             (    (if (= "@" (substr @each-name (- (strlen @each-name) 1)))
  112.                                                                     (    ;Apply patches with spatch
  113.                                                                         (set file (tackon dir2 @each-name))
  114.                                                                         (patch)
  115.                                                                     )
  116.                                                                     (    ;Copy the file directly
  117.                                                                         (set newfile (tackon dir2 @each-name))
  118.                                                                         (copynew)
  119.                                                                     )
  120.                                                                 )
  121.                                                             )
  122.                                                         )
  123.                                                     )
  124.                                                 )
  125.                                             )
  126.                                         )
  127.                                     )
  128.                                 )
  129.                             )
  130.                         )
  131.                     )
  132.                 )
  133.  
  134.                 (set wversion (+ wversion 1) )
  135.             )
  136.         )
  137.     )
  138. )
  139.  
  140.  
  141. ;***************************************************************************
  142. ;Preserve CIN
  143. (procedure preserveCIN
  144. ; Save the CIN to a CIN file on the disk
  145.     (run ("%s %s >%s" (tackon prod "c/serfile") (tackon prod "READ.ME") (tackon prod "CIN")))
  146. ; set the CIN temporarily to XXXX-YYYY
  147.     (run ("%s %s CIN: %s" (tackon prod "c/serfile") (tackon prod "READ.ME") "XXXX-YYYY"))
  148.     (set CINsaved 1)
  149. )
  150.  
  151. ;***************************************************************************
  152. ;Restore Old State
  153. (procedure restoreCIN
  154. ;restore product assignment
  155.     (if    (= newassign 1)
  156.         (    (makeassign ("%s" prodname) ("C%s:" prodname))
  157.             (makeassign ("C%s" prodname))
  158.         )
  159.     )
  160. ; reset the CIN back to the customer's CIN
  161.     (if (= CINsaved 1)
  162.         (run ("%s %s CIN: `type %s`" (tackon prod "c/serfile") (tackon prod "READ.ME") (tackon prod "CIN")))
  163.     )
  164. )
  165.  
  166. ;***************************************************************************
  167. ; Get the version number from a file
  168. (procedure getVersion_File
  169.     (set version (getversion verfile))
  170.     (if (= 0 version)
  171.         (set version defver)
  172.         (    (set ver (/ version 65536))
  173.             (set version ("%ld" (+ (* 100 ver) (BITAND version $FFFF))) )
  174.         )
  175.     )
  176. )
  177.  
  178.  
  179. ;***************************************************************************
  180. ;***************************** MAIN ****************************************
  181. ;***************************************************************************
  182.  
  183. ;This can be replaced by checks for "copy of <product>" etc.
  184. (set prodname "CrossDOS")
  185. (set prod ("%s:" prodname))
  186.  
  187.  
  188. ;Starting version number
  189. (set verfile (tackon prod "Read.ME"))
  190. (getVersion_File)    ; return in 'version"
  191. (set startversion version)
  192.  
  193.  
  194. (set @abort-button "Abort Update")
  195. (onerror (restoreCIN) )
  196.  
  197. ;Check if the <product>: being referenced is the assignment or the disk
  198. (askdisk 
  199.     (prompt ("Please insert %s in any drive" prod))
  200.     (help "To update, you must use a copy of the latest release of "
  201.             ("the %s product disk you have.  " prodname)
  202.             ("In addition, the volume MUST BE named `%s'.  " prodname)
  203.             ("If the disk you have is labeled `Copy_of_%s', " prodname)
  204.             "relabel it using the Workbench menu selection `Icons/Rename...'." )
  205.     (dest ("%s" prodname))
  206. )
  207.  
  208. (if (<> prod (expandpath prod))
  209.     (    (makeassign ("C%s" prodname) prod)    ;temp reassign product assignment
  210.         (set newassign 1)
  211.         (makeassign prodname)        ;clear the product assignment
  212.     )
  213. )
  214.  
  215. ;Force user level to 1 or 2. This is unfortuntely required because otherwise
  216. ;we can't present a menu of choices to the user.
  217. (if (= @user-level 0) 
  218.     (
  219.         (user 1)
  220.         (set @user-level 0)
  221.     )
  222. )
  223.  
  224. ; Test to see if the first patch directory exists.  If not, it may be that the
  225. ; archive was not unarc'd with full path names preserved.
  226. (if (not (= 2 (exists  startversion  (noreq) ) ) )
  227.     (    (message "Could not find directory '" startversion "'.  Make sure you unarc "
  228.             "the archive with the option to preserve directories.\n"
  229.             "[Example: LHA x -x <archivename>]\n"
  230.             "OR\n"
  231.             "This archive of patch files does not update the release "
  232.             "you currently have."
  233.         )
  234.         (exit (restoreCIN) (quiet))
  235.     )
  236. )
  237.  
  238. (set currentver startversion)
  239.  
  240. ; Put diag/spatch into ram:.  Since this program is to be used quite frequently
  241. (set spatch "ram:SPatch")
  242. (set spatchsrc (tackon prod "diag/SPatch"))
  243. (if (exists "SPatch" (noreq) )    ; a new SPatch exists in the current directory. Use it instead
  244.     (    (delete (tackon prod "diag/lpatch"))    ;delete the old lpatch
  245.         (copyfiles (source "SPatch") (dest (pathonly spatchsrc)))
  246.     )
  247. )
  248. (copyfiles (source spatchsrc) (dest (pathonly spatch) ) )
  249.  
  250.  
  251. (preserveCIN)
  252.  
  253. (set wversion "S")
  254.  
  255. ;Delete phase
  256. (set wversion (+ 1 startversion))
  257. (set DeleteOnly 1)
  258. (set PatchOnly 0)
  259. (set CopyOnly 0)
  260. (DoPatch)
  261.  
  262. ;Patch phase
  263. (set wversion (+ 1 startversion))
  264. (set DeleteOnly 0)
  265. (set PatchOnly 1)
  266. (set CopyOnly 0)
  267. (DoPatch)
  268.  
  269. ;Copy phase
  270. (set wversion (+ 1 startversion))
  271. (set DeleteOnly 0)
  272. (set PatchOnly 0)
  273. (set CopyOnly 1)
  274. (DoPatch)
  275.  
  276. (set wversion (+ -1 wversion))
  277.  
  278. (set verfile (tackon prod "Read.ME"))
  279. (getVersion_File)    ; return in 'version'
  280. (set currentver version)
  281.  
  282. (set wversion ("%ld" wversion))
  283.  
  284. (if    (= startversion wversion)
  285.     (    (message ("Your %s disk is already at release %s.%s" prodname (substr wversion 0 1) (substr wversion 1)))
  286.     )
  287.     (if    (> startversion wversion)
  288.         (    (message ("Your %s disk is already updated past the releases in this archive" prodname))
  289.         )
  290.         (if    (< currentver wversion)
  291.             (    (message ("Your %s disk COULD NOT be updated to release %s.%s\n" prodname (substr wversion 0 1) (substr wversion 1))
  292.                         ("It appears to be at release %s.%s\n" (substr currentver 0 1) (substr currentver 1))
  293.                         ("Make sure you patch a GOOD copy of the %s product disk ONLY!" prodname)
  294.                 )
  295.             )
  296.             (if    (= currentver wversion)
  297.                 (    (message ("Your %s disk has been updated to release %s.%s" prodname (substr currentver 0 1) (substr currentver 1))
  298.                     )
  299.                 )
  300.             )
  301.         )
  302.     )
  303. )
  304.  
  305. (restoreCIN)
  306.  
  307. (exit (quiet))
  308.